<?php

namespace App\Models;

use DB;
use Illuminate\Database\Eloquent\Model;

class Guide extends Model
{
    protected $guarded = [];

    public static function groupWithCount($field)
    {
        $data = self::select([$field,DB::raw('Count('.$field.') as count')])->groupBy($field)->get();
        return $data;
    }

    public static function groupByProvince()
    {
        $data = self::pluck('id_code')->map(function ($val){
            return get_source($val);
        })->groupBy('province')->map(function ($val,$key){
            return count($val);
        });

        return [
            $data
        ];
    }
}